# Timing Matters: Analyzing Climate Policies and Adaptive Resilience
## Replication Package

**Authors:** Elisa D'Amico & Tofigh Maboudi  
**Journal:** Climate Policy  
**Year:** 2025

---

## Overview

This replication package contains all code and data necessary to reproduce the analyses in "Timing Matters: Analyzing Climate Policies and Adaptive Resilience."

---

## File Structure

### R Scripts (run in order)

1. **01_data_cleaning.R** - Data preparation and merging
2. **02_models.R** - Random Forest variable selection and main regression models
3. **03_robustness.R** - Model specification tests and diagnostic analyses
4. **04_visualizations.R** - Generate all figures for paper and appendices

### Data Files Required

See `DATA_REQUIREMENTS.md` for detailed information on all required data files.

---

## Software Requirements

### R Version
- R 4.0.0 or higher

### Required R Packages

```r
install.packages(c(
  "car", "changepoint", "countrycode", "data.table", "dplyr",
  "doParallel", "e1071", "foreach", "ggplot2", "lmtest", "mice",
  "parallel", "patchwork", "plm", "purrr", "randomForest",
  "readr", "readxl", "rnaturalearth", "sandwich", "sf",
  "showtext", "stringr", "tidyr", "tseries", "vdemdata", "zoo"
))
```

---

## Running the Replication

### Step 1: Data Preparation

Ensure all data files (listed in DATA_REQUIREMENTS.md) are in your working directory.

```r
source("01_data_cleaning.R")
```

**Output:** `pdata_clean.csv`

### Step 2: Main Models

```r
source("02_models.R")
```

**Outputs:**
- `rf_variable_importance.rds` - Random Forest results
- `model_results.rds` - Main regression results

### Step 3: Robustness Tests

```r
source("03_robustness.R")
```

**Output:** `diagnostic_results.rds`

### Step 4: Visualizations

```r
source("04_visualizations.R")
```

**Outputs:**
- Figure_A1_changepoint.png
- Figure_A2_rf_importance.png
- Figure_A3_trends.png
- Figure_A4_populism.png
- Figure_A5_climate_events.png
- Figure_maps.png

---

## Key Analyses

### Main Results (Tables 2-4)
Generated by `02_models.R`
- Time fixed effects panel regression
- Three temporal periods: Pre-2006, 2007-2015, 2016+
- Short-term (t-1) and long-term (t-7) effects

### Appendix A: Change Point Analysis
Generated by `04_visualizations.R` (Figure A.1)

### Appendix E: Random Forest Variable Importance
Generated by `02_models.R` and `04_visualizations.R` (Figure A.2)

### Appendix F: Model Specification Selection
Generated by `03_robustness.R` (Table A.5)

### Appendix G: Diagnostic Testing
Generated by `03_robustness.R` (Tables A.6-A.8)

### Appendix H: Granger Causality
Generated by `03_robustness.R` (Table A.9)

---

## Notes

1. **Font Requirements:** Visualizations use Times New Roman. Adjust font path in `04_visualizations.R` line 17 if needed.

2. **Parallel Processing:** `02_models.R` uses parallel processing. It will automatically detect and use available cores (n-1).

3. **Imputation:** Missing data imputation uses MICE with seed 1995 for reproducibility.

4. **Log Transformations:** Variables with |skewness| > 1 are log-transformed with small constant (1e-6) to handle zeros.

---

## Citation

If you use this code or data, please cite:

```
D'Amico, E., & Maboudi, T. (2025). Timing Matters: Analyzing Climate Policies 
and Adaptive Resilience. Climate Policy.
```

---

## Contact

For questions or issues with replication:
- Elisa D'Amico: elisa.damico@ucd.ie
- Tofigh Maboudi: tmaboudi@luc.edu

---

## License

This replication package is provided for academic use only.
